package com.vma.manageSystem.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;

import java.util.Arrays;

/**
 * Created by chenzui on 2017/3/7.
 */
public class AdminLoginInterceptor implements Interceptor {
    private static String[] excludeActionKeys = {"/appUser","login"};

    public void intercept(Invocation invocation) {
        try {
            if(!Arrays.asList(excludeActionKeys).contains(invocation.getMethodName())) {
                if(invocation.getController().getSessionAttr("staffId") == null){
                    invocation.getController().redirect("/shop/login/pages-login.html");
                }else {
                    invocation.invoke();
                }
            }else {
                invocation.invoke();
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
//    private static String[] excludeActionKeys = {"/appUser","login"};
//    @Override
//    public void intercept(Invocation invocation) {
//        System.out.println(invocation.getControllerKey()+"------"+invocation.getMethodName());
//        if(!Arrays.asList(excludeActionKeys).contains(invocation.getMethodName())){
//           if(invocation.getController().getSessionAttr("staffId") == null){
//               invocation.getController().render("/shop/login/pages-login.html");
//           }else {
//               invocation.invoke();
//           }
//       }else {
//           invocation.invoke();
//       }
//
//    }
}
